package gen

import "strings"

var WrapperMap map[string]string = make(map[string]string)
var FormatMap map[string]*Formatter = make(map[string]*Formatter)
var Params map[string]interface{} = make(map[string]interface{})
var List *ListPattern = nil

//类目录
var Catalog []string = make([]string, 0)

//当前文件
var CurrFile string

//当前行
var CurrLine string

//当前代码块
var CurrBlock ICodeBlock

type Formatter struct {
	RawType      string
	FieldType    string
	DefaultValue string
}

type ListPattern struct {
	Pattern      string
	DefaultValue string
}

func FormatterOf(line string) *Formatter {
	var format Formatter
	parts := strings.Split(strings.TrimSpace(line), " ")
	format.RawType = parts[1]
	format.FieldType = parts[2]
	if len(parts) > 3 {
		format.DefaultValue = parts[3]
	}
	return &format
}

func ListPatternOf(line string) *ListPattern {
	var listPattern ListPattern
	parts := strings.Split(strings.TrimSpace(line), " ")
	listPattern.Pattern = parts[1]
	if len(parts) > 2 {
		listPattern.DefaultValue = parts[2]
	}
	return &listPattern
}
